<?php
 //echo session_encode();
	// dumps info about a session 
	//echo session_encode();
  	$intItemNumber = 0;
  	$intCartSubTotal = 0;
	$intCatTotal = 0;	
	$intCartWeightTotal = 0;  
	
	if(session_encode()){
	   $session_array = explode(";",session_encode());
	}
		for ($x = 0; $x < count($session_array); $x++) { 
			if (substr($session_array[$x],0,7)=="sesItem"){
				
				//echo "session array ".$session_array[$x]."<br>";
				// look up eregi in PHP book to explain the following
				// find 'sesItem' and write to $match[1]
				// find numbers and write to $match[2] (productID)
				// find '|i:' and write to $match[3]
				// find numbers and write to $match[4] (quantity)

				//sesItem1|i:4

				if (eregi("(sesItem)([0-9]{1,9})(\|i\:)([0-9]{1,9})$",$session_array[$x], $match)){	
					//if (eregi("(sesItem)([0-9]{1,9})([^\"]*)([^a-z])([^\"]*)\"$",$session_array[$x], $match)){	
					
					/*	
						$strhtml .= "0 - $match[0] \n<br>"; 
						$strhtml .= "1 - $match[1] \n<br>"; 
						$strhtml .= "2 -Product ID $match[2] \n<br>";
						$strhtml .= "3 - $match[3] \n<br>";  
						$strhtml .= "4 -Quantity  $match[4] \n<br>";  
					//*/									 

						$strBasketItemProductSQL = "SELECT * FROM tblProduct WHERE tblProduct.ID =  '$match[2]'";
						$objBasketItemProduct = new MySqlResults($strBasketItemProductSQL);	

							if($objBasketItemProduct->ErrorMessages){
								array_push($ActionResults, $objBasketItemProduct->ErrorMessages);
							}

						//echo $strBasketItemProductSQL."<br>";
					
					$intCartSubTotal = $objBasketItemProduct->myrow["UnitPrice"] * $match[4];
					$intCartWeightTotal = $objBasketItemProduct->myrow[Weight] + $intCartWeightTotal;	
					//echo $intCartWeightTotal."<br>";
					$intCatTotal = $intCatTotal + $intCartSubTotal;
						
			          if($boOmitDetails){
			              $intItemNumber += $match[4];// count number of items in cart
			              $strhtml = "<div align='right'>Items : ".$intItemNumber."</div>";
			          }else{
							$strhtml .= "<hr>";
								if($objBasketItemProduct->myrow["QuantityPerUnit"]>1){
									$strhtml .= $objBasketItemProduct->myrow["QuantityPerUnit"]."&nbsp;";
								}
							$strhtml .= $objBasketItemProduct->myrow["Product"]."\n"; 
							$strhtml .=  "<div align='right'>qty $match[4] x&nbsp;".CURRENCY.$objBasketItemProduct->myrow["UnitPrice"]." = ".CURRENCY. number_format($match[4] * $objBasketItemProduct->myrow["UnitPrice"], 2, '.', '')."</div>";
			
			          }
				}
			}
		}
	
	
	//set order total for carriage charge processing
		$_SESSION['sesOrderTotal'] = $intCatTotal;
		session_register(sesOrderTotal);
		
		if (!$strhtml) {
			// If No Items in basket
			$strhtml = "<div align='right'>Empty&nbsp;</div>";
			$boBasketEmpty = TRUE;
		}else{

				if((DELIVERY_INCLUDED) && ($_SESSION['sesOrderTotal'] >= MIN_ORDER_VALUE )){
					//change from a constant to a session variable so the value can be changed on dislaying the basket
					$intCARRIAGE = "0.00";
				}else{
					$intCARRIAGE = MINIMUM_CARRIAGE;
	
				}		   
					
				//If carriage > 0	
				/*
				if 	($intCartWeightTotal > 0) {
					$strhtml .= "<div align='right'><br>".$intCartWeightTotal."kg</div>";
				}
				*/
	
		    	if($boOmitDetails){}else{
					$strhtml .= "<hr>
					<div align='right'>Sub Total&nbsp;:&nbsp;".CURRENCY.number_format($intCatTotal, 2, '.', '')."</div>";
						if($intCARRIAGE > 0){
							$strhtml .= "<div align='right'><br>Carriage&nbsp;:&nbsp;".CURRENCY.number_format($intCARRIAGE, 2, '.', '')."</div>";
						}else{
							$strhtml .= "<div align='right'><br>Carriage : Included</div>";
						}
				}

			$strhtml .= "
			<div align='right'><br>Total&nbsp;:&nbsp;".CURRENCY.number_format($intCatTotal + $intCARRIAGE, 2, '.', '')."</div>";

				if($boOmitDetails){}else{
						$strhtml .= "
						<div align='right'><br>".BASKET_MESSAGE."</div>
						<br>";
				}
				
				if($boOmitBasket){}else{
					echo $strhtml; 
				}
			unset($strhtml);
		}
		

?>
